public class Test2 {
    public static void main(String[] args) throws InterruptedException {
        //用于存储 20 个 线程
        Thread[] threads = new Thread[20];
        for (int i = 0; i < 20; i++) {
            final int threadNum = i;
            //创建线程，每个线程打印自己的序号
            threads[i] = new Thread(() -> {
                System.out.println(threadNum);
            });
            //启动线程
            threads[i].start();
        }
        // 等待所以子线程执行完毕
        for(Thread thread : threads) {
            thread.join();
        }
        //所有子线程执行完后，主线程打印 OK
        System.out.println("OK");
    }
}
